package project.teg.configuration;

import java.sql.Date;

import project.teg.common.Border;
import project.teg.common.types.DeviceType;
import project.teg.common.types.GestureShapeType;
import project.teg.common.types.GestureType;
import project.teg.common.types.ScreenFieldType;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Color;
import android.graphics.PointF;
import android.preference.PreferenceManager;

public class Gestures {

	public static int gridRows = 5;

	public static int gridColumns = 5;

	public static int numberOfCheckpoints = 5;

	public static int radius = 1;

	// new

	public static GestureType gestureType;

	public static GestureShapeType gestureShapeType;

	public static int pathColor;

	public static int beginCheckPointColor;

	public static int endCheckpointColor;

	public static int internalCheckpointColor;

	public static int backgroundColor;

	public static int interactiveObjectColor;

	public static boolean isBackgroundSolidColor;

	public static boolean isPathVisible;

	public static boolean isCheckpointIndexVisible;

	// NEW
	public static int minimalDistanceToCheckPoint = 50;

	public static void saveColor(String preferenceName, int color,
			Context context) {

		SharedPreferences app_preferences = PreferenceManager
				.getDefaultSharedPreferences(context);
		Editor editor = app_preferences.edit();

		if (preferenceName.equals("pathColor")) {
			pathColor = color;
			editor.putInt("pathColor", color);
		} else if (preferenceName.equals("beginCheckPointColor")) {
			beginCheckPointColor = color;
			editor.putInt("beginCheckPointColor", color);
		} else if (preferenceName.equals("endCheckpointColor")) {
			endCheckpointColor = color;
			editor.putInt("endCheckpointColor", color);
		} else if (preferenceName.equals("internalCheckpointColor")) {
			internalCheckpointColor = color;
			editor.putInt("internalCheckpointColor", color);
		} else if (preferenceName.equals("backgroundColor")) {
			backgroundColor = color;
			editor.putInt("backgroundColor", color);
		} else if (preferenceName.equals("interactiveObjectColor")) {
			interactiveObjectColor = color;
			editor.putInt("interactiveObjectColor", color);
		}

		editor.commit();
	}

	public static void GetColors(Context context) {

		SharedPreferences app_preferences = PreferenceManager
				.getDefaultSharedPreferences(context);

		pathColor = app_preferences.getInt("pathColor", Color.BLUE);
		beginCheckPointColor = app_preferences.getInt("beginCheckPointColor",
				Color.GREEN);
		endCheckpointColor = app_preferences.getInt("endCheckpointColor",
				Color.RED);
		internalCheckpointColor = app_preferences.getInt(
				"internalCheckpointColor", Color.GRAY);
		backgroundColor = app_preferences.getInt("backgroundColor",
				Color.LTGRAY);
		interactiveObjectColor = app_preferences.getInt(
				"interactiveObjectColor", Color.BLUE);

	}

	public static void GetAllValues(Context context) {

		SharedPreferences app_preferences = PreferenceManager
				.getDefaultSharedPreferences(context);

		gridRows = app_preferences.getInt("gridRows", 5);
		gridColumns = app_preferences.getInt("gridColumns", 5);
		numberOfCheckpoints = app_preferences.getInt("numberOfCheckpoints", 5);
		radius = app_preferences.getInt("radius", 1);

		switch (app_preferences.getInt("gestureType", 0)) {
		case 0:
			gestureType = GestureType.Path;
			break;
		case 1:
			gestureType = GestureType.Shape;
			break;
		default:
			// error
		}

		switch (app_preferences.getInt("gestureShapeType", 0)) {
		case 0:
			gestureShapeType = GestureShapeType.Circle;
			break;
		case 1:
			gestureShapeType = GestureShapeType.Custom;
			break;
		case 2:
			gestureShapeType = GestureShapeType.Square;
			break;
		case 3:
			gestureShapeType = GestureShapeType.Triangle;
			break;
		default:
			// error
		}

		pathColor = app_preferences.getInt("pathColor", Color.BLUE);
		beginCheckPointColor = app_preferences.getInt("beginCheckPointColor",
				Color.GREEN);
		endCheckpointColor = app_preferences.getInt("endCheckpointColor",
				Color.RED);
		internalCheckpointColor = app_preferences.getInt(
				"internalCheckpointColor", Color.GRAY);
		backgroundColor = app_preferences.getInt("backgroundColor",
				Color.LTGRAY);
		interactiveObjectColor = app_preferences.getInt(
				"interactiveObjectColor", Color.LTGRAY);

		isBackgroundSolidColor = app_preferences.getBoolean(
				"isBackgroundSolidColor", true);
		isPathVisible = app_preferences.getBoolean("isPathVisible", true);
		isCheckpointIndexVisible = app_preferences.getBoolean(
				"isCheckpointIndexVisible", true);
		minimalDistanceToCheckPoint = app_preferences.getInt("minimalDistanceToCheckPoint", 50);
	}

	public static void SeveAllValues(Context context) {

		SharedPreferences app_preferences = PreferenceManager
				.getDefaultSharedPreferences(context);

		Editor editor = app_preferences.edit();

		editor.putInt("gridRows", gridRows);
		editor.putInt("gridColumns", gridColumns);
		editor.putInt("numberOfCheckpoints", numberOfCheckpoints);
		editor.putInt("radius", radius);
		editor.putInt("gestureType", gestureType.ordinal());
		editor.putInt("gestureShapeType", gestureShapeType.ordinal());
		editor.putInt("pathColor", pathColor);
		editor.putInt("beginCheckPointColor", beginCheckPointColor);
		editor.putInt("endCheckpointColor", endCheckpointColor);
		editor.putInt("internalCheckpointColor", internalCheckpointColor);
		editor.putInt("backgroundColor", backgroundColor);
		editor.putInt("interactiveObjectColor", interactiveObjectColor);

		editor.putBoolean("isBackgroundSolidColor", isBackgroundSolidColor);
		editor.putBoolean("isPathVisible", isPathVisible);
		editor.putBoolean("isCheckpointIndexVisible", isCheckpointIndexVisible);
		editor.putInt("minimalDistanceToCheckPoint", minimalDistanceToCheckPoint);
		editor.commit();
	}

}
